package jrmob.yonyou.com.commonlib.app_config_tool.tool.base;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.View;

import jrmob.yonyou.com.commonlib.baseui.base.BaseApp_lib;


/**
 * 描述:UI 工具类
 * 
 * @上午9:11:06
 * @author zhangg
 */
public class UiUtils {
	private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";
	/**
	 * 
	 * @param tabNames
	 * @return
	 */
	public static String[] getStringArray(int tabNames) {
		return getResource().getStringArray(tabNames);
	}

	public static Resources getResource() {
		return  getContext().getResources();
	}
	public static Context getContext() {
		return BaseApp_lib.getBaseApp();
	}

	/**
	 * 
	 * @param dip
	 * @return
	 */
	public static int dip2px(int dip) {
		final float scale = getResource().getDisplayMetrics().density;
		return (int) (dip * scale + 0.5f);
	}
	/**
	 * 计算状态栏高度高度
	 * getStatusBarHeight
	 *
	 * @return
	 */
	public static int getStatusBarHeight() {
		return getInternalDimensionSize(Resources.getSystem(), STATUS_BAR_HEIGHT_RES_NAME);
	}

	private static int getInternalDimensionSize(Resources res, String key) {
		int result = 0;
		int resourceId = res.getIdentifier(key, "dimen", "android");
		if (resourceId > 0) {
			result = res.getDimensionPixelSize(resourceId);
		}
		return result;
	}
	/**
	 * 
	 * @param px
	 * @return
	 */
	public static int px2dip(int px) {
		final float scale = getResource().getDisplayMetrics().density;
		return (int) (px / scale + 0.5f);
	}



	public static View inflate(int id) {
		return View.inflate(getContext(), id, null);
	}

	@SuppressWarnings("deprecation")
	public static Drawable getDrawalbe(int id) {
		return getResource().getDrawable(id);
	}

	public static int getDimens(int homePictureHeight) {
		return (int) getResource().getDimension(homePictureHeight);
	}



}
